Private Sub OperateDocumentApproval() 'Prerequisites: You have set ApprovalTemplates and ApprovalStage by DI or SAP Business One Dim i As Integer Dim retcode As Long = 0 Dim msg As String = "" 'Enable the approval procedure in the company level Dim oadmin As AdminInfo = oCompanyService.GetAdminInfo() oadmin.EnableApprovalProcedureInDI = BoYesNoEnum.tYES oadmin.DocConfirmation = BoYesNoEnum.tYES oCompanyService.UpdateAdminInfo(oadmin) 'Create an A/R invoice which will trigger the approval procedure Dim INVdockey As String = 0 Dim INVobjtype As String = 0 Dim DemoInvoice As Documents = oCompany.GetBusinessObject(BoObjectTypes.oInvoices) DemoInvoice.CardCode = "C001" DemoInvoice.Lines.ItemCode = "I001" DemoInvoice.Lines.Quantity = 6 DemoInvoice.Lines.UnitPrice = 10 DemoInvoice.Lines.TaxCode = "X2" DemoInvoice.DocDate = Today Try 'Get the related approval templates 'Documents.Document_ApprovalRequests will be filled retcode = DemoInvoice.GetApprovalTemplates() Catch ex As Exception 'exception process MsgBox(ex.Message) End Try If retcode = 0 Then If (DemoInvoice.Document_ApprovalRequests.ApprovalTemplatesID > 0) Then 'Fill remark of Approval Request For i = 1 To DemoInvoice.Document_ApprovalRequests.Count DemoInvoice.Document_ApprovalRequests.SetCurrentLine(i - 1) DemoInvoice.Document_ApprovalRequests.Remarks = "Remark of Inv" & i & " AddedfromDI" Next i End If End If Try retcode = DemoInvoice.Add() Catch ex As Exception 'exception process MsgBox(ex.Message) End Try If retcode = 0 Then 'Get the last added object key and type INVdockey = oCompany.GetNewObjectKey() INVobjtype = oCompany.GetNewObjectType() Else oCompany.GetLastError(retcode, msg) MsgBox("Failed to add. Error: " & msg & " (" & Str(retcode) & ")") Exit Sub End If 'Get the approval request decision report Dim oApprovalRequestsService As ApprovalRequestsService = oCompany.GetCompanyService().GetBusinessService(ServiceTypes.ApprovalRequestsService) Dim oApprovalRequest As ApprovalRequest = oApprovalRequestsService.GetDataInterface(ApprovalRequestsServiceDataInterfaces.arsApprovalRequest) Dim oApproalRequestParams As ApprovalRequestParams = oApprovalRequestsService.GetDataInterface(ApprovalRequestsServiceDataInterfaces.arsApprovalRequestParams) Dim oApproalRequestsParams As ApprovalRequestsParams = oApprovalRequestsService.GetDataInterface(ApprovalRequestsServiceDataInterfaces.arsApprovalRequestsParams) Dim oDraft As Documents = oCompany.GetBusinessObject(BoObjectTypes.oDrafts) Dim oApprovalRequestDecision As ApprovalRequestDecision oApproalRequestsParams = oApprovalRequestsService.GetAllApprovalRequestsList For i = 0 To (oApproalRequestsParams.Count - 1) oApprovalRequest = oApprovalRequestsService.GetApprovalRequest(oApproalRequestsParams.Item(i)) 'Get the request you want If (oApprovalRequest.ObjectEntry <> INVdockey) Then Continue For ElseIf (oApprovalRequest.ObjectType = INVobjtype) Then oApprovalRequestDecision = oApprovalRequest.ApprovalRequestDecisions.Add() oApprovalRequestDecision.Status = BoApprovalRequestDecisionEnum.ardApproved '0-pending, 1-approved, 2-rejected. oApprovalRequestDecision.ApproverUserName = "manager1" oApprovalRequestDecision.ApproverPassword = "1234" oApprovalRequestDecision.Remarks = "manager1approve" oApprovalRequestsService.UpdateRequest(oApprovalRequest) Exit For End If Next 'After the approval, trun draft to document Try oDraft.GetByKey(oApprovalRequest.ObjectEntry) oDraft.SaveDraftToDocument() Catch ex As Exception MsgBox(ex.Message) End Try End Sub
|